var gather_all_item_approve_level = JSON.parse('{"CODE":0, "ACTION":"","LEVEL":"T1", "MSG":"","DATA":"","SCRIPTNAME":"gather_all_item_approve_level"}');

var sku_approve_level_approveList = []
if (!isNull(item_status)) {
    var sku_approve_level_approve_statusList = gather_all_item_approve_level_for_item_status(item_nbr, item_status, trait_nbr, store_id,
        store_type, item_store_json, item_dc_json, category_nbr, sub_category_nbr, trait_store, null, null);
    if (!isNull(sku_approve_level_approve_statusList)) {
        sku_approve_level_approve_statusList.forEach(function (sku_approve_level_approve_status) {
            sku_approve_level_approveList.push(sku_approve_level_approve_status)
        })
    }
}

if (!isNull(retail_tax)) {
    var price_change_approve_price_wave = func_price_change_approve_price_wave_define();
    var price_wave_percent_approve_list_map = item_price_or_cost_wave_approve_level(price_change_approve_price_wave);

    var gather_all_item_approve_level_for_price_or_cost_res = gather_all_item_approve_level_for_price_or_cost(item_nbr, retail_tax, trait_nbr, store_id,
        store_type, item_store_json, item_dc_json, category_nbr, sub_category_nbr, trait_store, price_wave_percent_approve_list_map, 'price',
        item_status, null, db2_vnpk_qty, iva_tax)
    var sku_approve_level_approve_priceList = gather_all_item_approve_level_for_price_or_cost_res.sku_approve_level_approve_price_or_costList
    if (!isNull(sku_approve_level_approve_priceList)) {
        sku_approve_level_approve_priceList.forEach(function (sku_approve_level_approve_price) {
            sku_approve_level_approveList.push(sku_approve_level_approve_price)
        })
    }
}

if (!isNull(cost)) {
    var cost_wave_percent_approve_list_map = item_price_or_cost_wave_approve_level(func_price_change_approve_cost_wave_define());
    var gather_all_item_approve_level_for_price_or_cost_res = gather_all_item_approve_level_for_price_or_cost(item_nbr, cost, trait_nbr, store_id,
        store_type, item_store_json, item_dc_json, category_nbr, sub_category_nbr, trait_store, cost_wave_percent_approve_list_map, 'cost',
        item_status, vnpk_qty, db2_vnpk_qty, iva_tax)
    var sku_approve_level_approve_costList = gather_all_item_approve_level_for_price_or_cost_res.sku_approve_level_approve_price_or_costList
    if (!isNull(sku_approve_level_approve_costList)) {
        sku_approve_level_approve_costList.forEach(function (sku_approve_level_approve_cost) {
            sku_approve_level_approveList.push(sku_approve_level_approve_cost)
        })
    }
}

if (!isNull(tax_rate)) {
    var find_tax_rate_approve_level_approveList = func_find_status_approve_level(null, null,
        null, tax_rate, null);
    find_tax_rate_approve_level_approveList.forEach(function (find_tax_rate_approve_level_approve) {
        sku_approve_level_approveList.push(find_tax_rate_approve_level_approve)
    })
}
if (!isNull(vnpk_qty)) {
    var find_vnpk_qty_approve_level_approveList = func_find_status_approve_level(null, null,
        null, null, vnpk_qty);
    find_vnpk_qty_approve_level_approveList.forEach(function (find_vnpk_qty_approve_level_approve) {
        sku_approve_level_approveList.push(find_vnpk_qty_approve_level_approve)
    })
}
if (!isNull(retail_tax)) {
    var item_tbff_flag = false
    if (!isNull(item_attributes)) {
        var tbffFlag = item_attributes.get('tbffFlag');
        if (!isNull(tbffFlag)) {
            item_tbff_flag = tbffFlag;
        }
    }
    if (item_tbff_flag) {
        sku_approve_level_approveList.push('CMO');
    }
}
sku_approve_level_approveList.push('BUYER');
sku_approve_level_approveList = listToUnique(sku_approve_level_approveList);
sku_approve_level_approveList = sku_approve_level_approveList.sort(function (a, b) {
    return func_define_approve_level_list(a) - func_define_approve_level_list(b);
});

var updateData = [];
var updateDataRequestSku = {
    tableName: 'price_change_request_sku',
    data: []
};
var skuItem = {
    id: id,
    sku_approve_process: sku_approve_level_approveList.join('-')
}
updateDataRequestSku.data.push(skuItem);
updateData.push(updateDataRequestSku);

gather_all_item_approve_level.CODE = 4;
gather_all_item_approve_level.ACTION = 'update';
gather_all_item_approve_level.MSG = '审批级别：' + sku_approve_level_approveList.join('-');
gather_all_item_approve_level.DATA = JSON.stringify(updateData);

JSON.stringify(gather_all_item_approve_level);